/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author anhvh_b00319
 */
@Entity
@Table(name = "Enrollment")
@NamedQueries({
    @NamedQuery(name = "Enrollment.findAll", query = "SELECT e FROM Enrollment e"),
    @NamedQuery(name = "Enrollment.findByEnrollID", query = "SELECT e FROM Enrollment e WHERE e.enrollID = :enrollID")})
public class Enrollment implements Serializable {

    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Enroll_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer enrollID;
    @JoinColumn(name = "Pro_ID", referencedColumnName = "Pro_ID")
    @ManyToOne(optional = false)
    private Program program;
    @JoinColumn(name = "Client_ID", referencedColumnName = "Client_ID")
    @ManyToOne(optional = false)
    private Client client;

    public Enrollment() {
    }

    public Enrollment(Program program) {
        this.program = program;
        client = new Client();
    }

    public Enrollment(Integer enrollID) {
        this.enrollID = enrollID;
    }

    public Integer getEnrollID() {
        return enrollID;
    }

    public void setEnrollID(Integer enrollID) {
        Integer oldEnrollID = this.enrollID;
        this.enrollID = enrollID;
        changeSupport.firePropertyChange("enrollID", oldEnrollID, enrollID);
    }

    public Program getProgram() {
        return program;
    }

    public void setProgram(Program program) {
        Program oldProgram = this.program;
        this.program = program;
        changeSupport.firePropertyChange("program", oldProgram, program);
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        Client oldClient = this.client;
        this.client = client;
        changeSupport.firePropertyChange("client", oldClient, client);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (enrollID != null ? enrollID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Enrollment)) {
            return false;
        }
        Enrollment other = (Enrollment) object;
        if ((this.enrollID == null && other.enrollID != null)
                || (this.enrollID != null && !this.enrollID.equals(other.enrollID))) {
            return false;
        }
        if (this.enrollID == null && other.enrollID == null) {
            try {
                if (this.program.equals(other.program) && this.client.equals(other.client)) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception e) {
                return false;
            }

        }
        return true;
    }

    @Override
    public String toString() {
        return "Entities.Enrollment[enrollID=" + enrollID + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
